package com.pilgrim.framework.controller.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.Objects;

/**
 * 基础响应结果
 *
 * @author wangyibin
 * @version 1.0.0
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseResultVO {

    @JsonIgnore
    @JSONField(serialize = false)
    private HttpStatus httpStatus;

    private Integer status;

    private String msg;

    private String error;

    private String path;

    private Long timestamp;

    public int getStatus() {
        if(Objects.isNull(status)) {
            return this.httpStatus.value();
        }
        return status;
    }

    public Long getTimestamp() {
        if(Objects.isNull(timestamp)) {
        return Long.valueOf(System.currentTimeMillis()) ;
        }
        return timestamp;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }
}
